package com.example.everything_is_possible;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

public class NetworkChangeReceiver extends BroadcastReceiver {
    @Override

    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectivityManager = (ConnectivityManager)

                context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

        if (networkInfo!= null&&networkInfo.isAvailable()) {
            Toast.makeText(context, "手机网络已开启！", Toast.LENGTH_SHORT).show();

        } else {
            Toast.makeText(context, "手机网络未开启！", Toast.LENGTH_SHORT).show();

        }

    }

}